package com.example.doctor.jpa;

import com.example.common.entity.Hanswer;
import com.example.doctor.dto.resp.NotesRsp;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;
import java.util.List;

/**
 * @author sifan
 * @PackagName:com.example.doctor.jpa
 * @ClassName: HanswerRepository
 * @Description:
 * @date:2021/1/26 15:30
 */
public interface HanswerRepository extends JpaRepository<Hanswer,Long> {

    @Modifying
    @Transactional
    @Query(value = "DELETE FROM h_answer WHERE t_id_bigint=?1",nativeQuery = true)
    void deleteByTid(Long tid);

    @Query(value = "SELECT a.create_time_datetime AS CreateTime,a.f_code_nvarchar AS " +
            "FCode,a.send_type_tinyint AS SendType,a.t_name_bvarchar AS " +
            "TName FROM followr_question_main a WHERE a.dc_id_bigint=?1 AND " +
            "answer_bit=TRUE ORDER BY create_time_datetime DESC",nativeQuery = true)
    List<NotesRsp> findByDcId(Long dcId);

    @Query(value = "SELECT * FROM h_answer WHERE q_id_bigint=?1",nativeQuery = true)
    List<Hanswer> findByQid(Long qId);
}
